// SPDX-FileCopyrightText: 2022 Limor Fried for Adafruit Industries
//
// SPDX-License-Identifier: MIT

/* Includes
 * --------------------------------------------------------------------------------------*/

#include <Arduino.h>
#include <Adafruit_NeoPixel.h>

#include "led_manager.h"

#include "btn_drv.h"

#include "ui_task.h"

/* 测光 */
#include "dlight_bh1750.h"

/* BLE 任务 */
#include "ble_server_task.h"

#include "servo_task.h"

/* Function Implementations
 * ----------------------------------------------------------------------*/

void setup()
{
	Serial.begin(115200);
	uint32_t wait_cnt = 5;
	while (!Serial && (wait_cnt-- > 0)) { /* 等待串口软件连接 */
		delay(1000);
	}

	// delay(3000);
	Serial.println("Adafruit Feather ESP32-S3 TFT");
	Serial.println("Build: " + String(__DATE__) + " " + String(__TIME__));

	setup_led();

	setup_btn();

	setup_bh1750();
	loop_bh1750_scan();

	setup_servo();

	setup_ui_task();

	setup_ble_server_task();
}

void loop()
{
	// 获取测光数值
	loop_bh1750_scan();

	// 再根据按键的状况绘制 GUI
	loop_ui_task();

	loop_ble_server_task();

	loop_servo_task();

}
